package cn.bestick.examsys.action;

import cn.bestick.examsys.dao.StudentDao;
import cn.bestick.examsys.model.Student;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.ServletRequestAware;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by IntelliJ IDEA.
 * User: Bestick
 * Date: 2016/4/5
 * Time: 18:12
 * Url: http://www.bestick.cn
 * Copyright © 2015-2016 All rights reserved
 * -----------------------------------------------------------
 * 会当凌绝顶，一览众山小。
 */
public class StudentAction extends ActionSupport implements ServletRequestAware {

    private HttpServletRequest request;
    private StudentDao studentDao = new StudentDao();
    private Student student;
    private String error;

    public String login() throws Exception {
        HttpSession session = request.getSession();
        Student currentUser = studentDao.login(student);
        if (currentUser == null) {
            error = "准考证号或密码错误";
            return ERROR;
        }
        session.setAttribute("currentUser", currentUser);
        return SUCCESS;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    @Override
    public void setServletRequest(HttpServletRequest httpServletRequest) {
        this.request = httpServletRequest;
    }
}
